{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# `auto_arima`\n",
    "\n",
    "Pmdarima bring R's [`auto.arima`](https://www.rdocumentation.org/packages/forecast/versions/7.3/topics/auto.arima) functionality to Python by wrapping statsmodel [`ARIMA`](https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/arima_model.py) and [`SARIMAX`](https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/statespace/sarimax.py) models into a singular scikit-learn-esque estimator ([`pmdarima.arima.ARIMA`](https://github.com/alkaline-ml/pmdarima/blob/master/pmdarima/arima/arima.py)) and adding several layers of degree and seasonal differencing tests to identify the optimal model parameters.\n",
    "\n",
    "__Pmdarima ARIMA models:__\n",
    "\n",
    "  - Are fully picklable for easy persistence and model deployment\n",
    "  - Can handle seasonal terms (unlike statsmodels ARIMAs)\n",
    "  - Follow sklearn model fit/predict conventions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "numpy version: '1.15.3'\n",
      "pmdarima version: '1.3.0-dev0'\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pmdarima as pm\n",
    "\n",
    "print('numpy version: %r' % np.__version__)\n",
    "print('pmdarima version: %r' % pm.__version__)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We'll start by defining an array of data from an R time-series, `wineind`:\n",
    "\n",
    "```r\n",
    "> forecast::wineind\n",
    "       Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep   Oct   Nov   Dec\n",
    "1980 15136 16733 20016 17708 18019 19227 22893 23739 21133 22591 26786 29740\n",
    "1981 15028 17977 20008 21354 19498 22125 25817 28779 20960 22254 27392 29945\n",
    "1982 16933 17892 20533 23569 22417 22084 26580 27454 24081 23451 28991 31386\n",
    "1983 16896 20045 23471 21747 25621 23859 25500 30998 24475 23145 29701 34365\n",
    "1984 17556 22077 25702 22214 26886 23191 27831 35406 23195 25110 30009 36242\n",
    "1985 18450 21845 26488 22394 28057 25451 24872 33424 24052 28449 33533 37351\n",
    "1986 19969 21701 26249 24493 24603 26485 30723 34569 26689 26157 32064 38870\n",
    "1987 21337 19419 23166 28286 24570 24001 33151 24878 26804 28967 33311 40226\n",
    "1988 20504 23060 23562 27562 23940 24584 34303 25517 23494 29095 32903 34379\n",
    "1989 16991 21109 23740 25552 21752 20294 29009 25500 24166 26960 31222 38641\n",
    "1990 14672 17543 25453 32683 22449 22316 27595 25451 25421 25288 32568 35110\n",
    "1991 16052 22146 21198 19543 22084 23816 29961 26773 26635 26972 30207 38687\n",
    "1992 16974 21697 24179 23757 25013 24019 30345 24488 25156 25650 30923 37240\n",
    "1993 17466 19463 24352 26805 25236 24735 29356 31234 22724 28496 32857 37198\n",
    "1994 13652 22784 23565 26323 23779 27549 29660 23356\n",
    "```\n",
    "\n",
    "Note that the frequency of the data is 12:\n",
    "\n",
    "```r\n",
    "> frequency(forecast::wineind)\n",
    "[1] 12\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pmdarima.datasets import load_wineind\n",
    "\n",
    "# this is a dataset from R\n",
    "wineind = load_wineind().astype(np.float64)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fitting an ARIMA\n",
    "\n",
    "We will first fit a seasonal ARIMA. Note that you do not need to call `auto_arima` in order to fit a model&mdash;if you know the order and seasonality of your data, you can simply fit an ARIMA with the defined hyper-parameters:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pmdarima.arima import ARIMA\n",
    "\n",
    "fit = ARIMA(order=(1, 1, 1), seasonal_order=(0, 1, 1, 12)).fit(y=wineind)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Also note that your data does not have to exhibit seasonality to work with an ARIMA. We could fit an ARIMA against the same data with no seasonal terms whatsoever (but it is unlikely that it will perform better; quite the opposite, likely)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "fit = ARIMA(order=(1, 1, 1), seasonal_order=None).fit(y=wineind)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Finding the optimal model hyper-parameters using `auto_arima`:\n",
    "\n",
    "If you are unsure (as is common) of the best parameters for your model, let `auto_arima` figure it out for you. `auto_arima` is similar to an ARIMA-specific grid search, but (by default) uses a more intelligent `stepwise` algorithm laid out in a paper by Hyndman and Khandakar (2008). If `stepwise` is False, the models will be fit similar to a gridsearch. Note that it is possible for `auto_arima` not to find a model that will converge; if this is the case, it will raise a `ValueError`.\n",
    "\n",
    "### Fitting a stepwise search:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fit ARIMA: order=(1, 1, 1) seasonal_order=(0, 1, 1, 12); AIC=3066.760, BIC=3082.229, Fit time=0.725 seconds\n",
      "Fit ARIMA: order=(0, 1, 0) seasonal_order=(0, 1, 0, 12); AIC=3133.376, BIC=3139.564, Fit time=0.029 seconds\n",
      "Fit ARIMA: order=(1, 1, 0) seasonal_order=(1, 1, 0, 12); AIC=3099.734, BIC=3112.109, Fit time=0.334 seconds\n",
      "Fit ARIMA: order=(0, 1, 1) seasonal_order=(0, 1, 1, 12); AIC=3066.930, BIC=3079.305, Fit time=0.229 seconds\n",
      "Fit ARIMA: order=(1, 1, 1) seasonal_order=(1, 1, 1, 12); AIC=3067.548, BIC=3086.110, Fit time=1.106 seconds\n",
      "Fit ARIMA: order=(1, 1, 1) seasonal_order=(0, 1, 0, 12); AIC=3088.088, BIC=3100.463, Fit time=0.144 seconds\n",
      "Fit ARIMA: order=(1, 1, 1) seasonal_order=(0, 1, 2, 12); AIC=3068.000, BIC=3086.563, Fit time=1.005 seconds\n",
      "Fit ARIMA: order=(1, 1, 1) seasonal_order=(1, 1, 2, 12); AIC=3068.915, BIC=3090.571, Fit time=2.380 seconds\n",
      "Fit ARIMA: order=(2, 1, 1) seasonal_order=(0, 1, 1, 12); AIC=3067.447, BIC=3086.010, Fit time=0.435 seconds\n",
      "Fit ARIMA: order=(1, 1, 0) seasonal_order=(0, 1, 1, 12); AIC=3094.571, BIC=3106.946, Fit time=0.242 seconds\n",
      "Fit ARIMA: order=(1, 1, 2) seasonal_order=(0, 1, 1, 12); AIC=3066.742, BIC=3085.305, Fit time=0.524 seconds\n",
      "Fit ARIMA: order=(2, 1, 3) seasonal_order=(0, 1, 1, 12); AIC=3070.634, BIC=3095.384, Fit time=1.342 seconds\n",
      "Fit ARIMA: order=(1, 1, 2) seasonal_order=(1, 1, 1, 12); AIC=3068.010, BIC=3089.666, Fit time=0.704 seconds\n",
      "Fit ARIMA: order=(1, 1, 2) seasonal_order=(0, 1, 0, 12); AIC=3090.957, BIC=3106.426, Fit time=0.139 seconds\n",
      "Fit ARIMA: order=(1, 1, 2) seasonal_order=(0, 1, 2, 12); AIC=3067.731, BIC=3089.387, Fit time=1.046 seconds\n",
      "Fit ARIMA: order=(1, 1, 2) seasonal_order=(1, 1, 2, 12); AIC=3069.703, BIC=3094.453, Fit time=2.791 seconds\n",
      "Fit ARIMA: order=(0, 1, 2) seasonal_order=(0, 1, 1, 12); AIC=nan, BIC=nan, Fit time=nan seconds\n",
      "Fit ARIMA: order=(2, 1, 2) seasonal_order=(0, 1, 1, 12); AIC=3068.673, BIC=3090.330, Fit time=0.650 seconds\n",
      "Fit ARIMA: order=(1, 1, 3) seasonal_order=(0, 1, 1, 12); AIC=3068.810, BIC=3090.467, Fit time=0.730 seconds\n",
      "Total fit time: 14.564 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table class=\"simpletable\">\n",
       "<caption>Statespace Model Results</caption>\n",
       "<tr>\n",
       "  <th>Dep. Variable:</th>                  <td>y</td>               <th>  No. Observations:  </th>    <td>176</td>   \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Model:</th>           <td>SARIMAX(1, 1, 2)x(0, 1, 1, 12)</td> <th>  Log Likelihood     </th> <td>-1527.371</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Date:</th>                   <td>Mon, 27 May 2019</td>        <th>  AIC                </th> <td>3066.742</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Time:</th>                       <td>11:17:17</td>            <th>  BIC                </th> <td>3085.305</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Sample:</th>                         <td>0</td>               <th>  HQIC               </th> <td>3074.278</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th></th>                             <td> - 176</td>             <th>                     </th>     <td> </td>    \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Covariance Type:</th>               <td>opg</td>              <th>                     </th>     <td> </td>    \n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "      <td></td>         <th>coef</th>     <th>std err</th>      <th>z</th>      <th>P>|z|</th>  <th>[0.025</th>    <th>0.975]</th>  \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>intercept</th> <td> -100.7331</td> <td>   72.197</td> <td>   -1.395</td> <td> 0.163</td> <td> -242.236</td> <td>   40.770</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ar.L1</th>     <td>   -0.5123</td> <td>    0.390</td> <td>   -1.312</td> <td> 0.189</td> <td>   -1.277</td> <td>    0.253</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ma.L1</th>     <td>   -0.0806</td> <td>    0.404</td> <td>   -0.200</td> <td> 0.842</td> <td>   -0.872</td> <td>    0.711</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ma.L2</th>     <td>   -0.4430</td> <td>    0.224</td> <td>   -1.978</td> <td> 0.048</td> <td>   -0.882</td> <td>   -0.004</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ma.S.L12</th>  <td>   -0.4025</td> <td>    0.054</td> <td>   -7.448</td> <td> 0.000</td> <td>   -0.508</td> <td>   -0.297</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>sigma2</th>    <td> 7.663e+06</td> <td>  7.3e+05</td> <td>   10.495</td> <td> 0.000</td> <td> 6.23e+06</td> <td> 9.09e+06</td>\n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "  <th>Ljung-Box (Q):</th>          <td>48.70</td> <th>  Jarque-Bera (JB):  </th> <td>21.57</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Prob(Q):</th>                <td>0.16</td>  <th>  Prob(JB):          </th> <td>0.00</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Heteroskedasticity (H):</th> <td>1.18</td>  <th>  Skew:              </th> <td>-0.61</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Prob(H) (two-sided):</th>    <td>0.54</td>  <th>  Kurtosis:          </th> <td>4.31</td> \n",
       "</tr>\n",
       "</table><br/><br/>Warnings:<br/>[1] Covariance matrix calculated using the outer product of gradients (complex-step).<br/>[2] Covariance matrix is singular or near-singular, with condition number 8.14e+14. Standard errors may be unstable."
      ],
      "text/plain": [
       "<class 'statsmodels.iolib.summary.Summary'>\n",
       "\"\"\"\n",
       "                                 Statespace Model Results                                 \n",
       "==========================================================================================\n",
       "Dep. Variable:                                  y   No. Observations:                  176\n",
       "Model:             SARIMAX(1, 1, 2)x(0, 1, 1, 12)   Log Likelihood               -1527.371\n",
       "Date:                            Mon, 27 May 2019   AIC                           3066.742\n",
       "Time:                                    11:17:17   BIC                           3085.305\n",
       "Sample:                                         0   HQIC                          3074.278\n",
       "                                            - 176                                         \n",
       "Covariance Type:                              opg                                         \n",
       "==============================================================================\n",
       "                 coef    std err          z      P>|z|      [0.025      0.975]\n",
       "------------------------------------------------------------------------------\n",
       "intercept   -100.7331     72.197     -1.395      0.163    -242.236      40.770\n",
       "ar.L1         -0.5123      0.390     -1.312      0.189      -1.277       0.253\n",
       "ma.L1         -0.0806      0.404     -0.200      0.842      -0.872       0.711\n",
       "ma.L2         -0.4430      0.224     -1.978      0.048      -0.882      -0.004\n",
       "ma.S.L12      -0.4025      0.054     -7.448      0.000      -0.508      -0.297\n",
       "sigma2      7.663e+06    7.3e+05     10.495      0.000    6.23e+06    9.09e+06\n",
       "===================================================================================\n",
       "Ljung-Box (Q):                       48.70   Jarque-Bera (JB):                21.57\n",
       "Prob(Q):                              0.16   Prob(JB):                         0.00\n",
       "Heteroskedasticity (H):               1.18   Skew:                            -0.61\n",
       "Prob(H) (two-sided):                  0.54   Kurtosis:                         4.31\n",
       "===================================================================================\n",
       "\n",
       "Warnings:\n",
       "[1] Covariance matrix calculated using the outer product of gradients (complex-step).\n",
       "[2] Covariance matrix is singular or near-singular, with condition number 8.14e+14. Standard errors may be unstable.\n",
       "\"\"\""
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# fitting a stepwise model:\n",
    "stepwise_fit = pm.auto_arima(wineind, start_p=1, start_q=1, max_p=3, max_q=3, m=12,\n",
    "                             start_P=0, seasonal=True, d=1, D=1, trace=True,\n",
    "                             error_action='ignore',  # don't want to know if an order does not work\n",
    "                             suppress_warnings=True,  # don't want convergence warnings\n",
    "                             stepwise=True)  # set to stepwise\n",
    "\n",
    "stepwise_fit.summary()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Fitting a random search\n",
    "\n",
    "If you don't want to use the `stepwise` search, `auto_arima` can fit a random search by enabling `random=True`. If your random search returns too many invalid (nan) models, you might try increasing `n_fits` or making it an exhaustive search (`stepwise=False, random=False`)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total fit time: 38.591 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table class=\"simpletable\">\n",
       "<caption>Statespace Model Results</caption>\n",
       "<tr>\n",
       "  <th>Dep. Variable:</th>                  <td>y</td>               <th>  No. Observations:  </th>    <td>176</td>   \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Model:</th>           <td>SARIMAX(2, 1, 3)x(1, 1, 1, 12)</td> <th>  Log Likelihood     </th> <td>-1524.252</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Date:</th>                   <td>Mon, 27 May 2019</td>        <th>  AIC                </th> <td>3066.504</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Time:</th>                       <td>11:19:38</td>            <th>  BIC                </th> <td>3094.348</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Sample:</th>                         <td>0</td>               <th>  HQIC               </th> <td>3077.809</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th></th>                             <td> - 176</td>             <th>                     </th>     <td> </td>    \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Covariance Type:</th>               <td>opg</td>              <th>                     </th>     <td> </td>    \n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "      <td></td>         <th>coef</th>     <th>std err</th>      <th>z</th>      <th>P>|z|</th>  <th>[0.025</th>    <th>0.975]</th>  \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>intercept</th> <td> -112.2831</td> <td>  131.424</td> <td>   -0.854</td> <td> 0.393</td> <td> -369.870</td> <td>  145.304</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ar.L1</th>     <td>   -1.7290</td> <td>    0.052</td> <td>  -33.349</td> <td> 0.000</td> <td>   -1.831</td> <td>   -1.627</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ar.L2</th>     <td>   -0.8938</td> <td>    0.053</td> <td>  -16.983</td> <td> 0.000</td> <td>   -0.997</td> <td>   -0.791</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ma.L1</th>     <td>    1.1245</td> <td>    0.066</td> <td>   17.022</td> <td> 0.000</td> <td>    0.995</td> <td>    1.254</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ma.L2</th>     <td>   -0.3031</td> <td>    0.085</td> <td>   -3.547</td> <td> 0.000</td> <td>   -0.471</td> <td>   -0.136</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ma.L3</th>     <td>   -0.6783</td> <td>    0.050</td> <td>  -13.698</td> <td> 0.000</td> <td>   -0.775</td> <td>   -0.581</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ar.S.L12</th>  <td>    0.1278</td> <td>    0.157</td> <td>    0.815</td> <td> 0.415</td> <td>   -0.179</td> <td>    0.435</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ma.S.L12</th>  <td>   -0.5523</td> <td>    0.154</td> <td>   -3.586</td> <td> 0.000</td> <td>   -0.854</td> <td>   -0.250</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>sigma2</th>    <td> 7.548e+06</td> <td>    0.003</td> <td> 2.24e+09</td> <td> 0.000</td> <td> 7.55e+06</td> <td> 7.55e+06</td>\n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "  <th>Ljung-Box (Q):</th>          <td>43.96</td> <th>  Jarque-Bera (JB):  </th> <td>16.51</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Prob(Q):</th>                <td>0.31</td>  <th>  Prob(JB):          </th> <td>0.00</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Heteroskedasticity (H):</th> <td>1.07</td>  <th>  Skew:              </th> <td>-0.58</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Prob(H) (two-sided):</th>    <td>0.80</td>  <th>  Kurtosis:          </th> <td>4.04</td> \n",
       "</tr>\n",
       "</table><br/><br/>Warnings:<br/>[1] Covariance matrix calculated using the outer product of gradients (complex-step).<br/>[2] Covariance matrix is singular or near-singular, with condition number 9.91e+24. Standard errors may be unstable."
      ],
      "text/plain": [
       "<class 'statsmodels.iolib.summary.Summary'>\n",
       "\"\"\"\n",
       "                                 Statespace Model Results                                 \n",
       "==========================================================================================\n",
       "Dep. Variable:                                  y   No. Observations:                  176\n",
       "Model:             SARIMAX(2, 1, 3)x(1, 1, 1, 12)   Log Likelihood               -1524.252\n",
       "Date:                            Mon, 27 May 2019   AIC                           3066.504\n",
       "Time:                                    11:19:38   BIC                           3094.348\n",
       "Sample:                                         0   HQIC                          3077.809\n",
       "                                            - 176                                         \n",
       "Covariance Type:                              opg                                         \n",
       "==============================================================================\n",
       "                 coef    std err          z      P>|z|      [0.025      0.975]\n",
       "------------------------------------------------------------------------------\n",
       "intercept   -112.2831    131.424     -0.854      0.393    -369.870     145.304\n",
       "ar.L1         -1.7290      0.052    -33.349      0.000      -1.831      -1.627\n",
       "ar.L2         -0.8938      0.053    -16.983      0.000      -0.997      -0.791\n",
       "ma.L1          1.1245      0.066     17.022      0.000       0.995       1.254\n",
       "ma.L2         -0.3031      0.085     -3.547      0.000      -0.471      -0.136\n",
       "ma.L3         -0.6783      0.050    -13.698      0.000      -0.775      -0.581\n",
       "ar.S.L12       0.1278      0.157      0.815      0.415      -0.179       0.435\n",
       "ma.S.L12      -0.5523      0.154     -3.586      0.000      -0.854      -0.250\n",
       "sigma2      7.548e+06      0.003   2.24e+09      0.000    7.55e+06    7.55e+06\n",
       "===================================================================================\n",
       "Ljung-Box (Q):                       43.96   Jarque-Bera (JB):                16.51\n",
       "Prob(Q):                              0.31   Prob(JB):                         0.00\n",
       "Heteroskedasticity (H):               1.07   Skew:                            -0.58\n",
       "Prob(H) (two-sided):                  0.80   Kurtosis:                         4.04\n",
       "===================================================================================\n",
       "\n",
       "Warnings:\n",
       "[1] Covariance matrix calculated using the outer product of gradients (complex-step).\n",
       "[2] Covariance matrix is singular or near-singular, with condition number 9.91e+24. Standard errors may be unstable.\n",
       "\"\"\""
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rs_fit = pm.auto_arima(wineind, start_p=1, start_q=1, max_p=3, max_q=3, m=12,\n",
    "                       start_P=0, seasonal=True, d=1, D=1, trace=True,\n",
    "                       n_jobs=-1,  # We can run this in parallel by controlling this option\n",
    "                       error_action='ignore',  # don't want to know if an order does not work\n",
    "                       suppress_warnings=True,  # don't want convergence warnings\n",
    "                       stepwise=False, random=True, random_state=42,  # we can fit a random search (not exhaustive)\n",
    "                       n_fits=25)\n",
    "\n",
    "rs_fit.summary()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Inspecting goodness of fit\n",
    "\n",
    "We can look at how well the model fits in-sample data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div class=\"bk-root\">\n",
       "        <a href=\"https://bokeh.pydata.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
       "        <span id=\"1001\">Loading BokehJS ...</span>\n",
       "    </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "\n",
       "(function(root) {\n",
       "  function now() {\n",
       "    return new Date();\n",
       "  }\n",
       "\n",
       "  var force = true;\n",
       "\n",
       "  if (typeof (root._bokeh_onload_callbacks) === \"undefined\" || force === true) {\n",
       "    root._bokeh_onload_callbacks = [];\n",
       "    root._bokeh_is_loading = undefined;\n",
       "  }\n",
       "\n",
       "  var JS_MIME_TYPE = 'application/javascript';\n",
       "  var HTML_MIME_TYPE = 'text/html';\n",
       "  var EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n",
       "  var CLASS_NAME = 'output_bokeh rendered_html';\n",
       "\n",
       "  /**\n",
       "   * Render data to the DOM node\n",
       "   */\n",
       "  function render(props, node) {\n",
       "    var script = document.createElement(\"script\");\n",
       "    node.appendChild(script);\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when an output is cleared or removed\n",
       "   */\n",
       "  function handleClearOutput(event, handle) {\n",
       "    var cell = handle.cell;\n",
       "\n",
       "    var id = cell.output_area._bokeh_element_id;\n",
       "    var server_id = cell.output_area._bokeh_server_id;\n",
       "    // Clean up Bokeh references\n",
       "    if (id != null && id in Bokeh.index) {\n",
       "      Bokeh.index[id].model.document.clear();\n",
       "      delete Bokeh.index[id];\n",
       "    }\n",
       "\n",
       "    if (server_id !== undefined) {\n",
       "      // Clean up Bokeh references\n",
       "      var cmd = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n",
       "      cell.notebook.kernel.execute(cmd, {\n",
       "        iopub: {\n",
       "          output: function(msg) {\n",
       "            var id = msg.content.text.trim();\n",
       "            if (id in Bokeh.index) {\n",
       "              Bokeh.index[id].model.document.clear();\n",
       "              delete Bokeh.index[id];\n",
       "            }\n",
       "          }\n",
       "        }\n",
       "      });\n",
       "      // Destroy server and session\n",
       "      var cmd = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n",
       "      cell.notebook.kernel.execute(cmd);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when a new output is added\n",
       "   */\n",
       "  function handleAddOutput(event, handle) {\n",
       "    var output_area = handle.output_area;\n",
       "    var output = handle.output;\n",
       "\n",
       "    // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n",
       "    if ((output.output_type != \"display_data\") || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n",
       "      return\n",
       "    }\n",
       "\n",
       "    var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
       "\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n",
       "      toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n",
       "      // store reference to embed id on output_area\n",
       "      output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
       "    }\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
       "      var bk_div = document.createElement(\"div\");\n",
       "      bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
       "      var script_attrs = bk_div.children[0].attributes;\n",
       "      for (var i = 0; i < script_attrs.length; i++) {\n",
       "        toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
       "      }\n",
       "      // store reference to server id on output_area\n",
       "      output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
       "    }\n",
       "  }\n",
       "\n",
       "  function register_renderer(events, OutputArea) {\n",
       "\n",
       "    function append_mime(data, metadata, element) {\n",
       "      // create a DOM node to render to\n",
       "      var toinsert = this.create_output_subarea(\n",
       "        metadata,\n",
       "        CLASS_NAME,\n",
       "        EXEC_MIME_TYPE\n",
       "      );\n",
       "      this.keyboard_manager.register_events(toinsert);\n",
       "      // Render to node\n",
       "      var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
       "      render(props, toinsert[toinsert.length - 1]);\n",
       "      element.append(toinsert);\n",
       "      return toinsert\n",
       "    }\n",
       "\n",
       "    /* Handle when an output is cleared or removed */\n",
       "    events.on('clear_output.CodeCell', handleClearOutput);\n",
       "    events.on('delete.Cell', handleClearOutput);\n",
       "\n",
       "    /* Handle when a new output is added */\n",
       "    events.on('output_added.OutputArea', handleAddOutput);\n",
       "\n",
       "    /**\n",
       "     * Register the mime type and append_mime function with output_area\n",
       "     */\n",
       "    OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
       "      /* Is output safe? */\n",
       "      safe: true,\n",
       "      /* Index of renderer in `output_area.display_order` */\n",
       "      index: 0\n",
       "    });\n",
       "  }\n",
       "\n",
       "  // register the mime type if in Jupyter Notebook environment and previously unregistered\n",
       "  if (root.Jupyter !== undefined) {\n",
       "    var events = require('base/js/events');\n",
       "    var OutputArea = require('notebook/js/outputarea').OutputArea;\n",
       "\n",
       "    if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
       "      register_renderer(events, OutputArea);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  \n",
       "  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n",
       "    root._bokeh_timeout = Date.now() + 5000;\n",
       "    root._bokeh_failed_load = false;\n",
       "  }\n",
       "\n",
       "  var NB_LOAD_WARNING = {'data': {'text/html':\n",
       "     \"<div style='background-color: #fdd'>\\n\"+\n",
       "     \"<p>\\n\"+\n",
       "     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
       "     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
       "     \"</p>\\n\"+\n",
       "     \"<ul>\\n\"+\n",
       "     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
       "     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
       "     \"</ul>\\n\"+\n",
       "     \"<code>\\n\"+\n",
       "     \"from bokeh.resources import INLINE\\n\"+\n",
       "     \"output_notebook(resources=INLINE)\\n\"+\n",
       "     \"</code>\\n\"+\n",
       "     \"</div>\"}};\n",
       "\n",
       "  function display_loaded() {\n",
       "    var el = document.getElementById(\"1001\");\n",
       "    if (el != null) {\n",
       "      el.textContent = \"BokehJS is loading...\";\n",
       "    }\n",
       "    if (root.Bokeh !== undefined) {\n",
       "      if (el != null) {\n",
       "        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
       "      }\n",
       "    } else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(display_loaded, 100)\n",
       "    }\n",
       "  }\n",
       "\n",
       "\n",
       "  function run_callbacks() {\n",
       "    try {\n",
       "      root._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n",
       "    }\n",
       "    finally {\n",
       "      delete root._bokeh_onload_callbacks\n",
       "    }\n",
       "    console.info(\"Bokeh: all callbacks have finished\");\n",
       "  }\n",
       "\n",
       "  function load_libs(js_urls, callback) {\n",
       "    root._bokeh_onload_callbacks.push(callback);\n",
       "    if (root._bokeh_is_loading > 0) {\n",
       "      console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
       "      return null;\n",
       "    }\n",
       "    if (js_urls == null || js_urls.length === 0) {\n",
       "      run_callbacks();\n",
       "      return null;\n",
       "    }\n",
       "    console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
       "    root._bokeh_is_loading = js_urls.length;\n",
       "    for (var i = 0; i < js_urls.length; i++) {\n",
       "      var url = js_urls[i];\n",
       "      var s = document.createElement('script');\n",
       "      s.src = url;\n",
       "      s.async = false;\n",
       "      s.onreadystatechange = s.onload = function() {\n",
       "        root._bokeh_is_loading--;\n",
       "        if (root._bokeh_is_loading === 0) {\n",
       "          console.log(\"Bokeh: all BokehJS libraries loaded\");\n",
       "          run_callbacks()\n",
       "        }\n",
       "      };\n",
       "      s.onerror = function() {\n",
       "        console.warn(\"failed to load library \" + url);\n",
       "      };\n",
       "      console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
       "      document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "    }\n",
       "  };var element = document.getElementById(\"1001\");\n",
       "  if (element == null) {\n",
       "    console.log(\"Bokeh: ERROR: autoload.js configured with elementid '1001' but no matching script tag was found. \")\n",
       "    return false;\n",
       "  }\n",
       "\n",
       "  var js_urls = [\"https://cdn.pydata.org/bokeh/release/bokeh-1.0.1.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-widgets-1.0.1.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-tables-1.0.1.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-gl-1.0.1.min.js\"];\n",
       "\n",
       "  var inline_js = [\n",
       "    function(Bokeh) {\n",
       "      Bokeh.set_log_level(\"info\");\n",
       "    },\n",
       "    \n",
       "    function(Bokeh) {\n",
       "      \n",
       "    },\n",
       "    function(Bokeh) {\n",
       "      console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-1.0.1.min.css\");\n",
       "      Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-1.0.1.min.css\");\n",
       "      console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-1.0.1.min.css\");\n",
       "      Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-1.0.1.min.css\");\n",
       "      console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-tables-1.0.1.min.css\");\n",
       "      Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-tables-1.0.1.min.css\");\n",
       "    }\n",
       "  ];\n",
       "\n",
       "  function run_inline_js() {\n",
       "    \n",
       "    if ((root.Bokeh !== undefined) || (force === true)) {\n",
       "      for (var i = 0; i < inline_js.length; i++) {\n",
       "        inline_js[i].call(root, root.Bokeh);\n",
       "      }if (force === true) {\n",
       "        display_loaded();\n",
       "      }} else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(run_inline_js, 100);\n",
       "    } else if (!root._bokeh_failed_load) {\n",
       "      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
       "      root._bokeh_failed_load = true;\n",
       "    } else if (force !== true) {\n",
       "      var cell = $(document.getElementById(\"1001\")).parents('.cell').data().cell;\n",
       "      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
       "    }\n",
       "\n",
       "  }\n",
       "\n",
       "  if (root._bokeh_is_loading === 0) {\n",
       "    console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
       "    run_inline_js();\n",
       "  } else {\n",
       "    load_libs(js_urls, function() {\n",
       "      console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n",
       "      run_inline_js();\n",
       "    });\n",
       "  }\n",
       "}(window));"
      ],
      "application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n  function now() {\n    return new Date();\n  }\n\n  var force = true;\n\n  if (typeof (root._bokeh_onload_callbacks) === \"undefined\" || force === true) {\n    root._bokeh_onload_callbacks = [];\n    root._bokeh_is_loading = undefined;\n  }\n\n  \n\n  \n  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n    root._bokeh_timeout = Date.now() + 5000;\n    root._bokeh_failed_load = false;\n  }\n\n  var NB_LOAD_WARNING = {'data': {'text/html':\n     \"<div style='background-color: #fdd'>\\n\"+\n     \"<p>\\n\"+\n     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n     \"</p>\\n\"+\n     \"<ul>\\n\"+\n     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n     \"</ul>\\n\"+\n     \"<code>\\n\"+\n     \"from bokeh.resources import INLINE\\n\"+\n     \"output_notebook(resources=INLINE)\\n\"+\n     \"</code>\\n\"+\n     \"</div>\"}};\n\n  function display_loaded() {\n    var el = document.getElementById(\"1001\");\n    if (el != null) {\n      el.textContent = \"BokehJS is loading...\";\n    }\n    if (root.Bokeh !== undefined) {\n      if (el != null) {\n        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n      }\n    } else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(display_loaded, 100)\n    }\n  }\n\n\n  function run_callbacks() {\n    try {\n      root._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n    }\n    finally {\n      delete root._bokeh_onload_callbacks\n    }\n    console.info(\"Bokeh: all callbacks have finished\");\n  }\n\n  function load_libs(js_urls, callback) {\n    root._bokeh_onload_callbacks.push(callback);\n    if (root._bokeh_is_loading > 0) {\n      console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n      return null;\n    }\n    if (js_urls == null || js_urls.length === 0) {\n      run_callbacks();\n      return null;\n    }\n    console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n    root._bokeh_is_loading = js_urls.length;\n    for (var i = 0; i < js_urls.length; i++) {\n      var url = js_urls[i];\n      var s = document.createElement('script');\n      s.src = url;\n      s.async = false;\n      s.onreadystatechange = s.onload = function() {\n        root._bokeh_is_loading--;\n        if (root._bokeh_is_loading === 0) {\n          console.log(\"Bokeh: all BokehJS libraries loaded\");\n          run_callbacks()\n        }\n      };\n      s.onerror = function() {\n        console.warn(\"failed to load library \" + url);\n      };\n      console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n      document.getElementsByTagName(\"head\")[0].appendChild(s);\n    }\n  };var element = document.getElementById(\"1001\");\n  if (element == null) {\n    console.log(\"Bokeh: ERROR: autoload.js configured with elementid '1001' but no matching script tag was found. \")\n    return false;\n  }\n\n  var js_urls = [\"https://cdn.pydata.org/bokeh/release/bokeh-1.0.1.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-widgets-1.0.1.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-tables-1.0.1.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-gl-1.0.1.min.js\"];\n\n  var inline_js = [\n    function(Bokeh) {\n      Bokeh.set_log_level(\"info\");\n    },\n    \n    function(Bokeh) {\n      \n    },\n    function(Bokeh) {\n      console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-1.0.1.min.css\");\n      Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-1.0.1.min.css\");\n      console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-1.0.1.min.css\");\n      Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-1.0.1.min.css\");\n      console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-tables-1.0.1.min.css\");\n      Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-tables-1.0.1.min.css\");\n    }\n  ];\n\n  function run_inline_js() {\n    \n    if ((root.Bokeh !== undefined) || (force === true)) {\n      for (var i = 0; i < inline_js.length; i++) {\n        inline_js[i].call(root, root.Bokeh);\n      }if (force === true) {\n        display_loaded();\n      }} else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(run_inline_js, 100);\n    } else if (!root._bokeh_failed_load) {\n      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n      root._bokeh_failed_load = true;\n    } else if (force !== true) {\n      var cell = $(document.getElementById(\"1001\")).parents('.cell').data().cell;\n      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n    }\n\n  }\n\n  if (root._bokeh_is_loading === 0) {\n    console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n    run_inline_js();\n  } else {\n    load_libs(js_urls, function() {\n      console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n      run_inline_js();\n    });\n  }\n}(window));"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.plotting import figure, show, output_notebook\n",
    "import pandas as pd\n",
    "\n",
    "# init bokeh\n",
    "output_notebook()\n",
    "\n",
    "def plot_arima(truth, forecasts, title=\"ARIMA\", xaxis_label='Time',\n",
    "               yaxis_label='Value', c1='#A6CEE3', c2='#B2DF8A', \n",
    "               forecast_start=None, **kwargs):\n",
    "    \n",
    "    # make truth and forecasts into pandas series\n",
    "    n_truth = truth.shape[0]\n",
    "    n_forecasts = forecasts.shape[0]\n",
    "    \n",
    "    # always plot truth the same\n",
    "    truth = pd.Series(truth, index=np.arange(truth.shape[0]))\n",
    "    \n",
    "    # if no defined forecast start, start at the end\n",
    "    if forecast_start is None:\n",
    "        idx = np.arange(n_truth, n_truth + n_forecasts)\n",
    "    else:\n",
    "        idx = np.arange(forecast_start, n_forecasts)\n",
    "    forecasts = pd.Series(forecasts, index=idx)\n",
    "    \n",
    "    # set up the plot\n",
    "    p = figure(title=title, plot_height=400, **kwargs)\n",
    "    p.grid.grid_line_alpha=0.3\n",
    "    p.xaxis.axis_label = xaxis_label\n",
    "    p.yaxis.axis_label = yaxis_label\n",
    "    \n",
    "    # add the lines\n",
    "    p.line(truth.index, truth.values, color=c1, legend='Observed')\n",
    "    p.line(forecasts.index, forecasts.values, color=c2, legend='Forecasted')\n",
    "    \n",
    "    return p"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  -66.61074424, 10098.89197661, 12090.04716934, 16290.75198825,\n",
       "       15943.17987042, 17257.4782733 , 17797.61571866, 20199.85515377,\n",
       "       21475.00800993, 20787.12947566])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "in_sample_preds = stepwise_fit.predict_in_sample()\n",
    "in_sample_preds[:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"ee27dc60-626c-4dd9-ac6b-7c04e3245b75\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"f417cf84-f5d2-4696-b7af-a74f7a166e5c\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1013\",\"type\":\"LinearAxis\"}],\"left\":[{\"id\":\"1018\",\"type\":\"LinearAxis\"}],\"plot_height\":400,\"renderers\":[{\"id\":\"1013\",\"type\":\"LinearAxis\"},{\"id\":\"1017\",\"type\":\"Grid\"},{\"id\":\"1018\",\"type\":\"LinearAxis\"},{\"id\":\"1022\",\"type\":\"Grid\"},{\"id\":\"1031\",\"type\":\"BoxAnnotation\"},{\"id\":\"1049\",\"type\":\"Legend\"},{\"id\":\"1041\",\"type\":\"GlyphRenderer\"},{\"id\":\"1054\",\"type\":\"GlyphRenderer\"}],\"title\":{\"id\":\"1002\",\"type\":\"Title\"},\"toolbar\":{\"id\":\"1029\",\"type\":\"Toolbar\"},\"x_range\":{\"id\":\"1005\",\"type\":\"DataRange1d\"},\"x_scale\":{\"id\":\"1009\",\"type\":\"LinearScale\"},\"y_range\":{\"id\":\"1007\",\"type\":\"DataRange1d\"},\"y_scale\":{\"id\":\"1011\",\"type\":\"LinearScale\"}},\"id\":\"1003\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1014\",\"type\":\"BasicTicker\"},{\"attributes\":{\"line_color\":\"#FF0000\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1052\",\"type\":\"Line\"},{\"attributes\":{\"axis_label\":\"Time\",\"formatter\":{\"id\":\"1044\",\"type\":\"BasicTickFormatter\"},\"plot\":{\"id\":\"1003\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"1014\",\"type\":\"BasicTicker\"}},\"id\":\"1013\",\"type\":\"LinearAxis\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1023\",\"type\":\"PanTool\"},{\"id\":\"1024\",\"type\":\"WheelZoomTool\"},{\"id\":\"1025\",\"type\":\"BoxZoomTool\"},{\"id\":\"1026\",\"type\":\"SaveTool\"},{\"id\":\"1027\",\"type\":\"ResetTool\"},{\"id\":\"1028\",\"type\":\"HelpTool\"}]},\"id\":\"1029\",\"type\":\"Toolbar\"},{\"attributes\":{\"callback\":null,\"data\":{\"x\":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175],\"y\":{\"__ndarray__\":\"AAAAAACQzUAAAAAAQFfQQAAAAAAAjNNAAAAAAABL0UAAAAAAwJjRQAAAAADAxtJAAAAAAEBb1kAAAAAAwC7XQAAAAABAo9RAAAAAAMAP1kAAAAAAgCjaQAAAAAAAC91AAAAAAABazUAAAAAAQI7RQAAAAAAAitNAAAAAAIDa1EAAAAAAgArTQAAAAABAm9VAAAAAAEA22UAAAAAAwBrcQAAAAAAAeNRAAAAAAIC71UAAAAAAAMDaQAAAAABAPt1AAAAAAECJ0EAAAAAAAHnRQAAAAABADdRAAAAAAEAE10AAAAAAQOTVQAAAAAAAkdVAAAAAAAD12UAAAAAAgM/aQAAAAABAhNdAAAAAAMDm1kAAAAAAwE/cQAAAAACApt5AAAAAAACA0EAAAAAAQJPTQAAAAADA69ZAAAAAAMA81UAAAAAAQAXZQAAAAADATNdAAAAAAADn2EAAAAAAgEXeQAAAAADA5tdAAAAAAECa1kAAAAAAQAHdQAAAAACgx+BAAAAAAAAl0UAAAAAAQI/VQAAAAACAGdlAAAAAAICx1UAAAAAAgEHaQAAAAADApdZAAAAAAMAt20AAAAAAwEnhQAAAAADAptZAAAAAAICF2EAAAAAAQE7dQAAAAABAsuFAAAAAAIAE0kAAAAAAQFXVQAAAAAAA3tlAAAAAAIDe1UAAAAAAQGbbQAAAAADA2thAAAAAAABK2EAAAAAAAFLgQAAAAAAAfddAAAAAAEDI20AAAAAAoF/gQAAAAADgPOJAAAAAAECA00AAAAAAQDHVQAAAAABAotlAAAAAAEDr10AAAAAAwAbYQAAAAABA3dlAAAAAAMAA3kAAAAAAIOHgQAAAAABAENpAAAAAAECL2UAAAAAAAFDfQAAAAADA+uJAAAAAAEDW1EAAAAAAwPbSQAAAAACAn9ZAAAAAAICf20AAAAAAgP7XQAAAAABAcNdAAAAAAOAv4EAAAAAAgEvYQAAAAAAALdpAAAAAAMBJ3EAAAAAA4EPgQAAAAABApONAAAAAAAAG1EAAAAAAAIXWQAAAAACAAtdAAAAAAIDq2kAAAAAAAGHXQAAAAAAAAthAAAAAAOC/4EAAAAAAQOvYQAAAAACA8dZAAAAAAMBp3EAAAAAA4BDgQAAAAABgyeBAAAAAAMCX0EAAAAAAQJ3UQAAAAAAAL9dAAAAAAAD02EAAAAAAAD7VQAAAAACA0dNAAAAAAEBU3EAAAAAAAOfYQAAAAACAmddAAAAAAABU2kAAAAAAgH3eQAAAAAAg3uJAAAAAAACozEAAAAAAwCHRQAAAAABA29hAAAAAAMDq30AAAAAAQOzVQAAAAAAAy9VAAAAAAMDy2kAAAAAAwNrYQAAAAABA09hAAAAAAACy2EAAAAAAAM7fQAAAAADAJOFAAAAAAABaz0AAAAAAgKDVQAAAAACAs9RAAAAAAMAV00AAAAAAAJHVQAAAAAAAQtdAAAAAAEBC3UAAAAAAQCXaQAAAAADAAtpAAAAAAABX2kAAAAAAwH/dQAAAAADg4+JAAAAAAICT0EAAAAAAQDDVQAAAAADAnNdAAAAAAEAz10AAAAAAQG3YQAAAAADAdNdAAAAAAECi3UAAAAAAAOrXQAAAAAAAkdhAAAAAAIAM2UAAAAAAwDLeQAAAAAAAL+JAAAAAAIAO0UAAAAAAwAHTQAAAAAAAyNdAAAAAAEAt2kAAAAAAAKXYQAAAAADAJ9hAAAAAAACr3EAAAAAAgIDeQAAAAAAAMdZAAAAAAADU20AAAAAAIAvgQAAAAADAKeJAAAAAAACqykAAAAAAAEDWQAAAAABAA9dAAAAAAMC02UAAAAAAwDjXQAAAAABA59pAAAAAAAD33EAAAAAAAM/WQA==\",\"dtype\":\"float64\",\"shape\":[176]}},\"selected\":{\"id\":\"1062\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"1061\",\"type\":\"UnionRenderers\"}},\"id\":\"1038\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1046\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1073\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1011\",\"type\":\"LinearScale\"},{\"attributes\":{\"data_source\":{\"id\":\"1038\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"1039\",\"type\":\"Line\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1040\",\"type\":\"Line\"},\"selection_glyph\":null,\"view\":{\"id\":\"1042\",\"type\":\"CDSView\"}},\"id\":\"1041\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1023\",\"type\":\"PanTool\"},{\"attributes\":{\"dimension\":1,\"grid_line_alpha\":{\"value\":0.3},\"plot\":{\"id\":\"1003\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"1019\",\"type\":\"BasicTicker\"}},\"id\":\"1022\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1009\",\"type\":\"LinearScale\"},{\"attributes\":{\"label\":{\"value\":\"Observed\"},\"renderers\":[{\"id\":\"1041\",\"type\":\"GlyphRenderer\"}]},\"id\":\"1050\",\"type\":\"LegendItem\"},{\"attributes\":{\"callback\":null},\"id\":\"1007\",\"type\":\"DataRange1d\"},{\"attributes\":{\"axis_label\":\"Value\",\"formatter\":{\"id\":\"1046\",\"type\":\"BasicTickFormatter\"},\"plot\":{\"id\":\"1003\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"1019\",\"type\":\"BasicTicker\"}},\"id\":\"1018\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1061\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"callback\":null},\"id\":\"1005\",\"type\":\"DataRange1d\"},{\"attributes\":{\"items\":[{\"id\":\"1050\",\"type\":\"LegendItem\"},{\"id\":\"1064\",\"type\":\"LegendItem\"}],\"plot\":{\"id\":\"1003\",\"subtype\":\"Figure\",\"type\":\"Plot\"}},\"id\":\"1049\",\"type\":\"Legend\"},{\"attributes\":{\"plot\":null,\"text\":\"Original Series & In-sample Predictions\"},\"id\":\"1002\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1019\",\"type\":\"BasicTicker\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1053\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"1026\",\"type\":\"SaveTool\"},{\"attributes\":{\"data_source\":{\"id\":\"1051\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"1052\",\"type\":\"Line\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1053\",\"type\":\"Line\"},\"selection_glyph\":null,\"view\":{\"id\":\"1055\",\"type\":\"CDSView\"}},\"id\":\"1054\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1028\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1024\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"grid_line_alpha\":{\"value\":0.3},\"plot\":{\"id\":\"1003\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"1014\",\"type\":\"BasicTicker\"}},\"id\":\"1017\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1062\",\"type\":\"Selection\"},{\"attributes\":{\"overlay\":{\"id\":\"1031\",\"type\":\"BoxAnnotation\"}},\"id\":\"1025\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"source\":{\"id\":\"1038\",\"type\":\"ColumnDataSource\"}},\"id\":\"1042\",\"type\":\"CDSView\"},{\"attributes\":{\"source\":{\"id\":\"1051\",\"type\":\"ColumnDataSource\"}},\"id\":\"1055\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1044\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1027\",\"type\":\"ResetTool\"},{\"attributes\":{\"callback\":null,\"data\":{\"x\":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175],\"y\":{\"__ndarray__\":\"fa79bhanUMAnHEoscrnDQIATpQkGncdAwaQmQWDRz0Aue/4FlyPPQHWYB5xe2tBApzzvZ2dh0UAK39a69rnTQMoPPIPA+NRAQUZUSchM1EAE927lr9rVQOIQj813WNpA5rP73PNP4kDCuI2bCLLaQNhJXtSpsdtApNAMjq991kCVyTMNZFDXQLRIcj4F+9VAwsmWSaoU2UAGcwKvWFPZQIKqvxzl29hAT4WYNu5S10DM2tdrh+/ZQOTU1BvSr9tA+Fm1rT1j1kAQPTfENtjVQGpQHT0l9tZAVa6zdlgS1kC7Z15c2bnVQLxDlrYtVNdA1l1nUDPU2UBIEteAWvbbQEYLMJlx89VAMcjQhsfN10D6Rku7QAfbQG1JhXZB4t1A3nRjRADF00Bpjh8n6NbTQJv4a3c6cdZAw0ylA8I82ED+0lVght/VQN+r34AWCdhADKjj3fTk2kAzyHvllrnbQPtjSRJDmthA82LGZVfm10DEiuIBwmncQOy/AkGf1d5AoLX19jZC00BmnPoEAWLUQP5175slLthAXlxdgjfM10DHGNlB5r7YQOmVtwMdtthAiuqxiSb02UCwIhBSmoveQMpugF31NdpA/QTVz7GN10DkPSR/zEveQKPP1OOMd+BA9yFHsAxh00DOsnMgTMrVQOnquyH1RNlA2kSDbwwY10CkEjxdUvXZQBATCeKwINhAapvqPUTB20DPTWrEZhrgQFIh838PaddAfM6s/sra10D53oCltaveQNHy+YGE8eFA21mR3rWx00DD5QFXh9jWQMC4w21NLtpA1hjX6tDK1kAVHB2P09HbQEugQFTsgNdAELE7seUe2kDhkJBHPCrhQJtApXyrjdhAZpV2j68k3ECdukUK9rjfQI7iP52AH+JAWh0raNvm00ChsEmzd2/WQDbbDaprIdlA0m6yPkIv1kBsnbVtjlTaQNgZSdb2jdhAHA0J2+6q20B0WTRMozvhQPYqR7tnXdVA0qnVg3HD2UCcPsUXDqDeQG7v1dkLtuJAanVu4NKe1EBUwjyHiRrUQJ2WLr6f+dhA+pjeE+a72UClCDgnpzHZQJSkfbq7pNdAADHxtoSq3kDT1lzttLHcQGdd0JORlNhA8gEvNl0Q2kDo1dyetIvfQEmtm8pi3eJAvHsKb9em0UBhx2J58hbTQMXYJcF0VdVAX2djXz3+2ED6B8aGsQPWQCr4QaNs8tVAHk+sRhZT3UBy9ZLlMtrWQAqusspvgdVAtPFa5rLg2UClxCCs8e/dQK/ZPE5+vOBAIXxAY5x90UDPUArCZYXSQNx86VwY29RAy+XPkA6H2EAAkOCbJ6vXQKbg2ImhT9VArYYz7Yp43kB1rd/4xvnXQFWPcIp2TtdAGj7Dnx2L2kB8VmYLbN3dQBbbTeVKPuJAfjitKxEZzEAFKjLt6vvRQIUj9nNUaNhA7xyNixqw20BM3HoYpG3RQOePIhHafdNABhO/G/Vd2kDfuFu9j1nYQKDZDrRR59dAxcKWGCbS2UAR5NDNEJLfQDwkQ+EvO+FAQuOCrrZe0EDr0zH/HHfUQKy1WGyzmdZANBM+5nfF10AznfPme/XVQGCBa68tzddAvJm2Lmda3UDz25g5LYHaQFOJ19KQ09hA3fdXg/y92UASQA5rqm3dQOzh76v5JeJAFm9p3ijpzkAL+cAlVr/UQP1ui2yrx9VA9PVVKmgR10Ddm6jO8OXXQCCz/igqq9dAuGRa5Bjv3UCu7pLkUZTYQLDVI8gkV9tAzsZj9lrE2EDb5ZVG8eTfQDCov9a8juJAhp/c3hBh0UBGf7i5+oLSQEgW7gqRRdhAh6nbd1ZQ2EAhYnWkk4bYQFwvwbIm/tZAvpVY8w4a3kD85ZM5QfrbQA==\",\"dtype\":\"float64\",\"shape\":[176]}},\"selected\":{\"id\":\"1073\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"1072\",\"type\":\"UnionRenderers\"}},\"id\":\"1051\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"label\":{\"value\":\"Forecasted\"},\"renderers\":[{\"id\":\"1054\",\"type\":\"GlyphRenderer\"}]},\"id\":\"1064\",\"type\":\"LegendItem\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"value\":\"lightgrey\"},\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":{\"value\":1.0},\"line_color\":{\"value\":\"black\"},\"line_dash\":[4,4],\"line_width\":{\"value\":2},\"plot\":null,\"render_mode\":\"css\",\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1031\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1040\",\"type\":\"Line\"},{\"attributes\":{\"line_color\":\"#A6CEE3\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1039\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"1072\",\"type\":\"UnionRenderers\"}],\"root_ids\":[\"1003\"]},\"title\":\"Bokeh Application\",\"version\":\"1.0.1\"}};\n",
       "  var render_items = [{\"docid\":\"f417cf84-f5d2-4696-b7af-a74f7a166e5c\",\"roots\":{\"1003\":\"ee27dc60-626c-4dd9-ac6b-7c04e3245b75\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        embed_document(root);\n",
       "        clearInterval(timer);\n",
       "      }\n",
       "      attempts++;\n",
       "      if (attempts > 100) {\n",
       "        console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        clearInterval(timer);\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1003"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "show(plot_arima(wineind, in_sample_preds, \n",
    "                title=\"Original Series & In-sample Predictions\", \n",
    "                c2='#FF0000', forecast_start=0))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Predicting future values\n",
    "\n",
    "After your model is fit, you can forecast future values using the `predict` function, just like in sci-kit learn:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([21966.69715352, 25983.70920565, 30225.30978848, 35417.12496267,\n",
       "       13011.3618805 , 19639.41027742, 21506.58176159, 23674.33998321,\n",
       "       21685.76394174, 23669.77818948, 26955.35255979, 22755.2506162 ,\n",
       "       19808.16131764, 23578.7818493 , 27845.86719673, 32923.89426476,\n",
       "       10475.6877784 , 17024.74533391, 18831.64797186, 20929.546713  ,\n",
       "       18876.02414315, 20792.57512611, 24011.97546913, 19745.03906623,\n",
       "       16731.45362497])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "next_25 = stepwise_fit.predict(n_periods=25)\n",
    "next_25"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"430f9ab6-9102-4727-84c0-838c36a56371\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"b16aa5a9-b36b-498f-8590-e3038c137502\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1146\",\"type\":\"LinearAxis\"}],\"left\":[{\"id\":\"1151\",\"type\":\"LinearAxis\"}],\"plot_height\":400,\"renderers\":[{\"id\":\"1146\",\"type\":\"LinearAxis\"},{\"id\":\"1150\",\"type\":\"Grid\"},{\"id\":\"1151\",\"type\":\"LinearAxis\"},{\"id\":\"1155\",\"type\":\"Grid\"},{\"id\":\"1164\",\"type\":\"BoxAnnotation\"},{\"id\":\"1182\",\"type\":\"Legend\"},{\"id\":\"1174\",\"type\":\"GlyphRenderer\"},{\"id\":\"1187\",\"type\":\"GlyphRenderer\"}],\"title\":{\"id\":\"1135\",\"type\":\"Title\"},\"toolbar\":{\"id\":\"1162\",\"type\":\"Toolbar\"},\"x_range\":{\"id\":\"1138\",\"type\":\"DataRange1d\"},\"x_scale\":{\"id\":\"1142\",\"type\":\"LinearScale\"},\"y_range\":{\"id\":\"1140\",\"type\":\"DataRange1d\"},\"y_scale\":{\"id\":\"1144\",\"type\":\"LinearScale\"}},\"id\":\"1136\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"value\":\"lightgrey\"},\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":{\"value\":1.0},\"line_color\":{\"value\":\"black\"},\"line_dash\":[4,4],\"line_width\":{\"value\":2},\"plot\":null,\"render_mode\":\"css\",\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1164\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1152\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1177\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"source\":{\"id\":\"1171\",\"type\":\"ColumnDataSource\"}},\"id\":\"1175\",\"type\":\"CDSView\"},{\"attributes\":{\"line_color\":\"#A6CEE3\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1172\",\"type\":\"Line\"},{\"attributes\":{\"overlay\":{\"id\":\"1164\",\"type\":\"BoxAnnotation\"}},\"id\":\"1158\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1179\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1215\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"callback\":null},\"id\":\"1138\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1142\",\"type\":\"LinearScale\"},{\"attributes\":{\"dimension\":1,\"grid_line_alpha\":{\"value\":0.3},\"plot\":{\"id\":\"1136\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"1152\",\"type\":\"BasicTicker\"}},\"id\":\"1155\",\"type\":\"Grid\"},{\"attributes\":{\"callback\":null,\"data\":{\"x\":[176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200],\"y\":{\"__ndarray__\":\"p84pnqxz1UDXE6Bj7V/ZQD8Mk9NThN1AvbSx/yNL4UASphlSrmnJQOo2/EHaLdNAiveUO6UA1UDV8EjClR7XQBvna+RwLdVAvELbzXEd10AJ71aQ1lLaQMeEGArQONZA7jQHUwpY00AjpdEJsgbXQAO2JoB3MdtAMR/RnXwT4EDSWR8J2HXEQMcBjbMvoNBAyfteeOlj0kDYhFj9YnDUQMqzj4sBb9JAjLndziRO1ED7FhZu/nLXQLyiD4BCSNNAvwgxCN1W0EA=\",\"dtype\":\"float64\",\"shape\":[25]}},\"selected\":{\"id\":\"1216\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"1215\",\"type\":\"UnionRenderers\"}},\"id\":\"1184\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1161\",\"type\":\"HelpTool\"},{\"attributes\":{\"label\":{\"value\":\"Observed\"},\"renderers\":[{\"id\":\"1174\",\"type\":\"GlyphRenderer\"}]},\"id\":\"1183\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"1159\",\"type\":\"SaveTool\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1156\",\"type\":\"PanTool\"},{\"id\":\"1157\",\"type\":\"WheelZoomTool\"},{\"id\":\"1158\",\"type\":\"BoxZoomTool\"},{\"id\":\"1159\",\"type\":\"SaveTool\"},{\"id\":\"1160\",\"type\":\"ResetTool\"},{\"id\":\"1161\",\"type\":\"HelpTool\"}]},\"id\":\"1162\",\"type\":\"Toolbar\"},{\"attributes\":{\"items\":[{\"id\":\"1183\",\"type\":\"LegendItem\"},{\"id\":\"1197\",\"type\":\"LegendItem\"}],\"plot\":{\"id\":\"1136\",\"subtype\":\"Figure\",\"type\":\"Plot\"}},\"id\":\"1182\",\"type\":\"Legend\"},{\"attributes\":{\"callback\":null,\"data\":{\"x\":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175],\"y\":{\"__ndarray__\":\"AAAAAACQzUAAAAAAQFfQQAAAAAAAjNNAAAAAAABL0UAAAAAAwJjRQAAAAADAxtJAAAAAAEBb1kAAAAAAwC7XQAAAAABAo9RAAAAAAMAP1kAAAAAAgCjaQAAAAAAAC91AAAAAAABazUAAAAAAQI7RQAAAAAAAitNAAAAAAIDa1EAAAAAAgArTQAAAAABAm9VAAAAAAEA22UAAAAAAwBrcQAAAAAAAeNRAAAAAAIC71UAAAAAAAMDaQAAAAABAPt1AAAAAAECJ0EAAAAAAAHnRQAAAAABADdRAAAAAAEAE10AAAAAAQOTVQAAAAAAAkdVAAAAAAAD12UAAAAAAgM/aQAAAAABAhNdAAAAAAMDm1kAAAAAAwE/cQAAAAACApt5AAAAAAACA0EAAAAAAQJPTQAAAAADA69ZAAAAAAMA81UAAAAAAQAXZQAAAAADATNdAAAAAAADn2EAAAAAAgEXeQAAAAADA5tdAAAAAAECa1kAAAAAAQAHdQAAAAACgx+BAAAAAAAAl0UAAAAAAQI/VQAAAAACAGdlAAAAAAICx1UAAAAAAgEHaQAAAAADApdZAAAAAAMAt20AAAAAAwEnhQAAAAADAptZAAAAAAICF2EAAAAAAQE7dQAAAAABAsuFAAAAAAIAE0kAAAAAAQFXVQAAAAAAA3tlAAAAAAIDe1UAAAAAAQGbbQAAAAADA2thAAAAAAABK2EAAAAAAAFLgQAAAAAAAfddAAAAAAEDI20AAAAAAoF/gQAAAAADgPOJAAAAAAECA00AAAAAAQDHVQAAAAABAotlAAAAAAEDr10AAAAAAwAbYQAAAAABA3dlAAAAAAMAA3kAAAAAAIOHgQAAAAABAENpAAAAAAECL2UAAAAAAAFDfQAAAAADA+uJAAAAAAEDW1EAAAAAAwPbSQAAAAACAn9ZAAAAAAICf20AAAAAAgP7XQAAAAABAcNdAAAAAAOAv4EAAAAAAgEvYQAAAAAAALdpAAAAAAMBJ3EAAAAAA4EPgQAAAAABApONAAAAAAAAG1EAAAAAAAIXWQAAAAACAAtdAAAAAAIDq2kAAAAAAAGHXQAAAAAAAAthAAAAAAOC/4EAAAAAAQOvYQAAAAACA8dZAAAAAAMBp3EAAAAAA4BDgQAAAAABgyeBAAAAAAMCX0EAAAAAAQJ3UQAAAAAAAL9dAAAAAAAD02EAAAAAAAD7VQAAAAACA0dNAAAAAAEBU3EAAAAAAAOfYQAAAAACAmddAAAAAAABU2kAAAAAAgH3eQAAAAAAg3uJAAAAAAACozEAAAAAAwCHRQAAAAABA29hAAAAAAMDq30AAAAAAQOzVQAAAAAAAy9VAAAAAAMDy2kAAAAAAwNrYQAAAAABA09hAAAAAAACy2EAAAAAAAM7fQAAAAADAJOFAAAAAAABaz0AAAAAAgKDVQAAAAACAs9RAAAAAAMAV00AAAAAAAJHVQAAAAAAAQtdAAAAAAEBC3UAAAAAAQCXaQAAAAADAAtpAAAAAAABX2kAAAAAAwH/dQAAAAADg4+JAAAAAAICT0EAAAAAAQDDVQAAAAADAnNdAAAAAAEAz10AAAAAAQG3YQAAAAADAdNdAAAAAAECi3UAAAAAAAOrXQAAAAAAAkdhAAAAAAIAM2UAAAAAAwDLeQAAAAAAAL+JAAAAAAIAO0UAAAAAAwAHTQAAAAAAAyNdAAAAAAEAt2kAAAAAAAKXYQAAAAADAJ9hAAAAAAACr3EAAAAAAgIDeQAAAAAAAMdZAAAAAAADU20AAAAAAIAvgQAAAAADAKeJAAAAAAACqykAAAAAAAEDWQAAAAABAA9dAAAAAAMC02UAAAAAAwDjXQAAAAABA59pAAAAAAAD33EAAAAAAAM/WQA==\",\"dtype\":\"float64\",\"shape\":[176]}},\"selected\":{\"id\":\"1195\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"1194\",\"type\":\"UnionRenderers\"}},\"id\":\"1171\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"line_color\":\"#B2DF8A\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1185\",\"type\":\"Line\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1186\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"1216\",\"type\":\"Selection\"},{\"attributes\":{\"data_source\":{\"id\":\"1171\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"1172\",\"type\":\"Line\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1173\",\"type\":\"Line\"},\"selection_glyph\":null,\"view\":{\"id\":\"1175\",\"type\":\"CDSView\"}},\"id\":\"1174\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1147\",\"type\":\"BasicTicker\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1173\",\"type\":\"Line\"},{\"attributes\":{\"source\":{\"id\":\"1184\",\"type\":\"ColumnDataSource\"}},\"id\":\"1188\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1156\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1144\",\"type\":\"LinearScale\"},{\"attributes\":{\"data_source\":{\"id\":\"1184\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"1185\",\"type\":\"Line\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1186\",\"type\":\"Line\"},\"selection_glyph\":null,\"view\":{\"id\":\"1188\",\"type\":\"CDSView\"}},\"id\":\"1187\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1195\",\"type\":\"Selection\"},{\"attributes\":{\"axis_label\":\"Value\",\"formatter\":{\"id\":\"1179\",\"type\":\"BasicTickFormatter\"},\"plot\":{\"id\":\"1136\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"1152\",\"type\":\"BasicTicker\"}},\"id\":\"1151\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1194\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"plot\":null,\"text\":\"ARIMA\"},\"id\":\"1135\",\"type\":\"Title\"},{\"attributes\":{\"callback\":null},\"id\":\"1140\",\"type\":\"DataRange1d\"},{\"attributes\":{\"label\":{\"value\":\"Forecasted\"},\"renderers\":[{\"id\":\"1187\",\"type\":\"GlyphRenderer\"}]},\"id\":\"1197\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"1160\",\"type\":\"ResetTool\"},{\"attributes\":{\"grid_line_alpha\":{\"value\":0.3},\"plot\":{\"id\":\"1136\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"1147\",\"type\":\"BasicTicker\"}},\"id\":\"1150\",\"type\":\"Grid\"},{\"attributes\":{\"axis_label\":\"Time\",\"formatter\":{\"id\":\"1177\",\"type\":\"BasicTickFormatter\"},\"plot\":{\"id\":\"1136\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"1147\",\"type\":\"BasicTicker\"}},\"id\":\"1146\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1157\",\"type\":\"WheelZoomTool\"}],\"root_ids\":[\"1136\"]},\"title\":\"Bokeh Application\",\"version\":\"1.0.1\"}};\n",
       "  var render_items = [{\"docid\":\"b16aa5a9-b36b-498f-8590-e3038c137502\",\"roots\":{\"1136\":\"430f9ab6-9102-4727-84c0-838c36a56371\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        embed_document(root);\n",
       "        clearInterval(timer);\n",
       "      }\n",
       "      attempts++;\n",
       "      if (attempts > 100) {\n",
       "        console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        clearInterval(timer);\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1136"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# call the plotting func\n",
    "show(plot_arima(wineind, next_25))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Updating your model\n",
    "\n",
    "ARIMAs create forecasts by using the latest observations. Over time, your forecasts will drift, and you'll need to update the model with the observed values. There are several solutions to this problem:\n",
    "\n",
    "* Fit a new ARIMA with the new data added to your training sample\n",
    "  - You can either re-use the order discovered in the `auto_arima` function, or re-run `auto_arima` altogether.\n",
    "* Use the `update` method (__preferred__). This will allow your model to update its parameters by taking several more MLE steps on new observations (controlled by the `maxiter` arg) starting from the parameters it's already discovered. This approach will help you avoid over-fitting.\n",
    "\n",
    "For this example, let's update our existing model with the `next_25` we just computed, as if they were actually observed values."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"simpletable\">\n",
       "<caption>Statespace Model Results</caption>\n",
       "<tr>\n",
       "  <th>Dep. Variable:</th>                  <td>y</td>               <th>  No. Observations:  </th>    <td>201</td>   \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Model:</th>           <td>SARIMAX(1, 1, 2)x(0, 1, 1, 12)</td> <th>  Log Likelihood     </th> <td>-1748.493</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Date:</th>                   <td>Mon, 27 May 2019</td>        <th>  AIC                </th> <td>3508.986</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Time:</th>                       <td>11:25:31</td>            <th>  BIC                </th> <td>3528.404</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Sample:</th>                         <td>0</td>               <th>  HQIC               </th> <td>3516.853</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th></th>                             <td> - 201</td>             <th>                     </th>     <td> </td>    \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Covariance Type:</th>               <td>opg</td>              <th>                     </th>     <td> </td>    \n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "      <td></td>         <th>coef</th>     <th>std err</th>      <th>z</th>      <th>P>|z|</th>  <th>[0.025</th>    <th>0.975]</th>  \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>intercept</th> <td> -100.7331</td> <td>   72.099</td> <td>   -1.397</td> <td> 0.162</td> <td> -242.045</td> <td>   40.578</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ar.L1</th>     <td>   -0.5122</td> <td>    0.390</td> <td>   -1.314</td> <td> 0.189</td> <td>   -1.277</td> <td>    0.252</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ma.L1</th>     <td>   -0.0806</td> <td>    0.403</td> <td>   -0.200</td> <td> 0.842</td> <td>   -0.871</td> <td>    0.710</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ma.L2</th>     <td>   -0.4431</td> <td>    0.224</td> <td>   -1.981</td> <td> 0.048</td> <td>   -0.882</td> <td>   -0.005</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ma.S.L12</th>  <td>   -0.4024</td> <td>    0.054</td> <td>   -7.458</td> <td> 0.000</td> <td>   -0.508</td> <td>   -0.297</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>sigma2</th>    <td> 7.663e+06</td> <td>  7.1e+05</td> <td>   10.789</td> <td> 0.000</td> <td> 6.27e+06</td> <td> 9.05e+06</td>\n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "  <th>Ljung-Box (Q):</th>          <td>54.62</td> <th>  Jarque-Bera (JB):  </th> <td>44.08</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Prob(Q):</th>                <td>0.06</td>  <th>  Prob(JB):          </th> <td>0.00</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Heteroskedasticity (H):</th> <td>0.54</td>  <th>  Skew:              </th> <td>-0.66</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Prob(H) (two-sided):</th>    <td>0.01</td>  <th>  Kurtosis:          </th> <td>4.97</td> \n",
       "</tr>\n",
       "</table><br/><br/>Warnings:<br/>[1] Covariance matrix calculated using the outer product of gradients (complex-step).<br/>[2] Covariance matrix is singular or near-singular, with condition number 7.7e+14. Standard errors may be unstable."
      ],
      "text/plain": [
       "<class 'statsmodels.iolib.summary.Summary'>\n",
       "\"\"\"\n",
       "                                 Statespace Model Results                                 \n",
       "==========================================================================================\n",
       "Dep. Variable:                                  y   No. Observations:                  201\n",
       "Model:             SARIMAX(1, 1, 2)x(0, 1, 1, 12)   Log Likelihood               -1748.493\n",
       "Date:                            Mon, 27 May 2019   AIC                           3508.986\n",
       "Time:                                    11:25:31   BIC                           3528.404\n",
       "Sample:                                         0   HQIC                          3516.853\n",
       "                                            - 201                                         \n",
       "Covariance Type:                              opg                                         \n",
       "==============================================================================\n",
       "                 coef    std err          z      P>|z|      [0.025      0.975]\n",
       "------------------------------------------------------------------------------\n",
       "intercept   -100.7331     72.099     -1.397      0.162    -242.045      40.578\n",
       "ar.L1         -0.5122      0.390     -1.314      0.189      -1.277       0.252\n",
       "ma.L1         -0.0806      0.403     -0.200      0.842      -0.871       0.710\n",
       "ma.L2         -0.4431      0.224     -1.981      0.048      -0.882      -0.005\n",
       "ma.S.L12      -0.4024      0.054     -7.458      0.000      -0.508      -0.297\n",
       "sigma2      7.663e+06    7.1e+05     10.789      0.000    6.27e+06    9.05e+06\n",
       "===================================================================================\n",
       "Ljung-Box (Q):                       54.62   Jarque-Bera (JB):                44.08\n",
       "Prob(Q):                              0.06   Prob(JB):                         0.00\n",
       "Heteroskedasticity (H):               0.54   Skew:                            -0.66\n",
       "Prob(H) (two-sided):                  0.01   Kurtosis:                         4.97\n",
       "===================================================================================\n",
       "\n",
       "Warnings:\n",
       "[1] Covariance matrix calculated using the outer product of gradients (complex-step).\n",
       "[2] Covariance matrix is singular or near-singular, with condition number 7.7e+14. Standard errors may be unstable.\n",
       "\"\"\""
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stepwise_fit.update(next_25, maxiter=10)  # take 10 more steps\n",
    "stepwise_fit.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "updated_data = np.concatenate([wineind, next_25])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"347b66bb-946e-44e7-a581-8409c3ae25e0\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"f316dd23-13d2-42dd-8b94-d2317d75f3ed\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1289\",\"type\":\"LinearAxis\"}],\"left\":[{\"id\":\"1294\",\"type\":\"LinearAxis\"}],\"plot_height\":400,\"renderers\":[{\"id\":\"1289\",\"type\":\"LinearAxis\"},{\"id\":\"1293\",\"type\":\"Grid\"},{\"id\":\"1294\",\"type\":\"LinearAxis\"},{\"id\":\"1298\",\"type\":\"Grid\"},{\"id\":\"1307\",\"type\":\"BoxAnnotation\"},{\"id\":\"1325\",\"type\":\"Legend\"},{\"id\":\"1317\",\"type\":\"GlyphRenderer\"},{\"id\":\"1330\",\"type\":\"GlyphRenderer\"}],\"title\":{\"id\":\"1278\",\"type\":\"Title\"},\"toolbar\":{\"id\":\"1305\",\"type\":\"Toolbar\"},\"x_range\":{\"id\":\"1281\",\"type\":\"DataRange1d\"},\"x_scale\":{\"id\":\"1285\",\"type\":\"LinearScale\"},\"y_range\":{\"id\":\"1283\",\"type\":\"DataRange1d\"},\"y_scale\":{\"id\":\"1287\",\"type\":\"LinearScale\"}},\"id\":\"1279\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1329\",\"type\":\"Line\"},{\"attributes\":{\"line_color\":\"#A6CEE3\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1315\",\"type\":\"Line\"},{\"attributes\":{\"data_source\":{\"id\":\"1327\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"1328\",\"type\":\"Line\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1329\",\"type\":\"Line\"},\"selection_glyph\":null,\"view\":{\"id\":\"1331\",\"type\":\"CDSView\"}},\"id\":\"1330\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"callback\":null,\"data\":{\"x\":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200],\"y\":{\"__ndarray__\":\"AAAAAACQzUAAAAAAQFfQQAAAAAAAjNNAAAAAAABL0UAAAAAAwJjRQAAAAADAxtJAAAAAAEBb1kAAAAAAwC7XQAAAAABAo9RAAAAAAMAP1kAAAAAAgCjaQAAAAAAAC91AAAAAAABazUAAAAAAQI7RQAAAAAAAitNAAAAAAIDa1EAAAAAAgArTQAAAAABAm9VAAAAAAEA22UAAAAAAwBrcQAAAAAAAeNRAAAAAAIC71UAAAAAAAMDaQAAAAABAPt1AAAAAAECJ0EAAAAAAAHnRQAAAAABADdRAAAAAAEAE10AAAAAAQOTVQAAAAAAAkdVAAAAAAAD12UAAAAAAgM/aQAAAAABAhNdAAAAAAMDm1kAAAAAAwE/cQAAAAACApt5AAAAAAACA0EAAAAAAQJPTQAAAAADA69ZAAAAAAMA81UAAAAAAQAXZQAAAAADATNdAAAAAAADn2EAAAAAAgEXeQAAAAADA5tdAAAAAAECa1kAAAAAAQAHdQAAAAACgx+BAAAAAAAAl0UAAAAAAQI/VQAAAAACAGdlAAAAAAICx1UAAAAAAgEHaQAAAAADApdZAAAAAAMAt20AAAAAAwEnhQAAAAADAptZAAAAAAICF2EAAAAAAQE7dQAAAAABAsuFAAAAAAIAE0kAAAAAAQFXVQAAAAAAA3tlAAAAAAIDe1UAAAAAAQGbbQAAAAADA2thAAAAAAABK2EAAAAAAAFLgQAAAAAAAfddAAAAAAEDI20AAAAAAoF/gQAAAAADgPOJAAAAAAECA00AAAAAAQDHVQAAAAABAotlAAAAAAEDr10AAAAAAwAbYQAAAAABA3dlAAAAAAMAA3kAAAAAAIOHgQAAAAABAENpAAAAAAECL2UAAAAAAAFDfQAAAAADA+uJAAAAAAEDW1EAAAAAAwPbSQAAAAACAn9ZAAAAAAICf20AAAAAAgP7XQAAAAABAcNdAAAAAAOAv4EAAAAAAgEvYQAAAAAAALdpAAAAAAMBJ3EAAAAAA4EPgQAAAAABApONAAAAAAAAG1EAAAAAAAIXWQAAAAACAAtdAAAAAAIDq2kAAAAAAAGHXQAAAAAAAAthAAAAAAOC/4EAAAAAAQOvYQAAAAACA8dZAAAAAAMBp3EAAAAAA4BDgQAAAAABgyeBAAAAAAMCX0EAAAAAAQJ3UQAAAAAAAL9dAAAAAAAD02EAAAAAAAD7VQAAAAACA0dNAAAAAAEBU3EAAAAAAAOfYQAAAAACAmddAAAAAAABU2kAAAAAAgH3eQAAAAAAg3uJAAAAAAACozEAAAAAAwCHRQAAAAABA29hAAAAAAMDq30AAAAAAQOzVQAAAAAAAy9VAAAAAAMDy2kAAAAAAwNrYQAAAAABA09hAAAAAAACy2EAAAAAAAM7fQAAAAADAJOFAAAAAAABaz0AAAAAAgKDVQAAAAACAs9RAAAAAAMAV00AAAAAAAJHVQAAAAAAAQtdAAAAAAEBC3UAAAAAAQCXaQAAAAADAAtpAAAAAAABX2kAAAAAAwH/dQAAAAADg4+JAAAAAAICT0EAAAAAAQDDVQAAAAADAnNdAAAAAAEAz10AAAAAAQG3YQAAAAADAdNdAAAAAAECi3UAAAAAAAOrXQAAAAAAAkdhAAAAAAIAM2UAAAAAAwDLeQAAAAAAAL+JAAAAAAIAO0UAAAAAAwAHTQAAAAAAAyNdAAAAAAEAt2kAAAAAAAKXYQAAAAADAJ9hAAAAAAACr3EAAAAAAgIDeQAAAAAAAMdZAAAAAAADU20AAAAAAIAvgQAAAAADAKeJAAAAAAACqykAAAAAAAEDWQAAAAABAA9dAAAAAAMC02UAAAAAAwDjXQAAAAABA59pAAAAAAAD33EAAAAAAAM/WQKfOKZ6sc9VA1xOgY+1f2UA/DJPTU4TdQL20sf8jS+FAEqYZUq5pyUDqNvxB2i3TQIr3lDulANVA1fBIwpUe10Ab52vkcC3VQLxC281xHddACe9WkNZS2kDHhBgK0DjWQO40B1MKWNNAI6XRCbIG10ADtiaAdzHbQDEf0Z18E+BA0lkfCdh1xEDHAY2zL6DQQMn7XnjpY9JA2IRY/WJw1EDKs4+LAW/SQIy53c4kTtRA+xYWbv5y10C8og+AQkjTQL8IMQjdVtBA\",\"dtype\":\"float64\",\"shape\":[201]}},\"selected\":{\"id\":\"1338\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"1337\",\"type\":\"UnionRenderers\"}},\"id\":\"1314\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1299\",\"type\":\"PanTool\"},{\"id\":\"1300\",\"type\":\"WheelZoomTool\"},{\"id\":\"1301\",\"type\":\"BoxZoomTool\"},{\"id\":\"1302\",\"type\":\"SaveTool\"},{\"id\":\"1303\",\"type\":\"ResetTool\"},{\"id\":\"1304\",\"type\":\"HelpTool\"}]},\"id\":\"1305\",\"type\":\"Toolbar\"},{\"attributes\":{\"source\":{\"id\":\"1327\",\"type\":\"ColumnDataSource\"}},\"id\":\"1331\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1299\",\"type\":\"PanTool\"},{\"attributes\":{\"line_color\":\"#B2DF8A\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1328\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"1337\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1300\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1368\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1338\",\"type\":\"Selection\"},{\"attributes\":{\"overlay\":{\"id\":\"1307\",\"type\":\"BoxAnnotation\"}},\"id\":\"1301\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"label\":{\"value\":\"Forecasted\"},\"renderers\":[{\"id\":\"1330\",\"type\":\"GlyphRenderer\"}]},\"id\":\"1340\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"1302\",\"type\":\"SaveTool\"},{\"attributes\":{\"callback\":null},\"id\":\"1281\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1303\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1369\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1304\",\"type\":\"HelpTool\"},{\"attributes\":{\"plot\":null,\"text\":\"ARIMA\"},\"id\":\"1278\",\"type\":\"Title\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1316\",\"type\":\"Line\"},{\"attributes\":{\"data_source\":{\"id\":\"1314\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"1315\",\"type\":\"Line\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1316\",\"type\":\"Line\"},\"selection_glyph\":null,\"view\":{\"id\":\"1318\",\"type\":\"CDSView\"}},\"id\":\"1317\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"callback\":null},\"id\":\"1283\",\"type\":\"DataRange1d\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"value\":\"lightgrey\"},\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":{\"value\":1.0},\"line_color\":{\"value\":\"black\"},\"line_dash\":[4,4],\"line_width\":{\"value\":2},\"plot\":null,\"render_mode\":\"css\",\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1307\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1285\",\"type\":\"LinearScale\"},{\"attributes\":{\"source\":{\"id\":\"1314\",\"type\":\"ColumnDataSource\"}},\"id\":\"1318\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1287\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1320\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"axis_label\":\"Time\",\"formatter\":{\"id\":\"1320\",\"type\":\"BasicTickFormatter\"},\"plot\":{\"id\":\"1279\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"1290\",\"type\":\"BasicTicker\"}},\"id\":\"1289\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1322\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1290\",\"type\":\"BasicTicker\"},{\"attributes\":{\"items\":[{\"id\":\"1326\",\"type\":\"LegendItem\"},{\"id\":\"1340\",\"type\":\"LegendItem\"}],\"plot\":{\"id\":\"1279\",\"subtype\":\"Figure\",\"type\":\"Plot\"}},\"id\":\"1325\",\"type\":\"Legend\"},{\"attributes\":{\"grid_line_alpha\":{\"value\":0.3},\"plot\":{\"id\":\"1279\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"1290\",\"type\":\"BasicTicker\"}},\"id\":\"1293\",\"type\":\"Grid\"},{\"attributes\":{\"label\":{\"value\":\"Observed\"},\"renderers\":[{\"id\":\"1317\",\"type\":\"GlyphRenderer\"}]},\"id\":\"1326\",\"type\":\"LegendItem\"},{\"attributes\":{\"axis_label\":\"Value\",\"formatter\":{\"id\":\"1322\",\"type\":\"BasicTickFormatter\"},\"plot\":{\"id\":\"1279\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"1295\",\"type\":\"BasicTicker\"}},\"id\":\"1294\",\"type\":\"LinearAxis\"},{\"attributes\":{\"callback\":null,\"data\":{\"x\":[201,202,203,204,205,206,207,208,209,210],\"y\":{\"__ndarray__\":\"UzQomNr000CSM68u+g7YQPISkmDT89xALK0l2njcu0A1ZTkfeZfKQM/UDeuc/c1At8zkYaH60ECWdjd4MNHNQHg5Ut0Vt9BAC03Lx0bL00A=\",\"dtype\":\"float64\",\"shape\":[10]}},\"selected\":{\"id\":\"1369\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"1368\",\"type\":\"UnionRenderers\"}},\"id\":\"1327\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1295\",\"type\":\"BasicTicker\"},{\"attributes\":{\"dimension\":1,\"grid_line_alpha\":{\"value\":0.3},\"plot\":{\"id\":\"1279\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"1295\",\"type\":\"BasicTicker\"}},\"id\":\"1298\",\"type\":\"Grid\"}],\"root_ids\":[\"1279\"]},\"title\":\"Bokeh Application\",\"version\":\"1.0.1\"}};\n",
       "  var render_items = [{\"docid\":\"f316dd23-13d2-42dd-8b94-d2317d75f3ed\",\"roots\":{\"1279\":\"347b66bb-946e-44e7-a581-8409c3ae25e0\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        embed_document(root);\n",
       "        clearInterval(timer);\n",
       "      }\n",
       "      attempts++;\n",
       "      if (attempts > 100) {\n",
       "        console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        clearInterval(timer);\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1279"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# visualize new forecasts\n",
    "show(plot_arima(updated_data, stepwise_fit.predict(n_periods=10)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [conda env:pmdenv]",
   "language": "python",
   "name": "conda-env-pmdenv-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
